package a66weding.com.jiehuntong.activity.home;

import android.content.Intent;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;


import com.andview.refreshview.XRefreshView;

import java.util.ArrayList;
import java.util.List;

import a66weding.com.jiehuntong.R;
import a66weding.com.jiehuntong.adapter.ClassificationAdapter;
import a66weding.com.jiehuntong.fragment.homeshopcase.BaseShopCaseFragment;
import a66weding.com.jiehuntong.fragment.homeshopcase.ShopAllCaseFragment;
import a66weding.com.jiehuntong.fragment.homeshopcase.ShopAllGoodsFragment;
import a66weding.com.jiehuntong.fragment.homeshopcase.ShopAllNewFragment;
import a66weding.com.jiehuntong.fragment.order.AllOrderFragment;
import a66weding.com.jiehuntong.fragment.order.WaitEvaluationOrderFragment;
import a66weding.com.jiehuntong.fragment.order.WaitPayOrderFragment;
import a66weding.com.jiehuntong.fragment.order.WaitReceiptOrderFragment;
import a66weding.com.jiehuntong.fragment.order.WaitShipOrderFragment;

public class HomeShopCaseActivity extends BaseHomeActivity implements View.OnClickListener {

    private LinearLayout mBackLay;
    private EditText mSearchEt;
    private ImageView mPhoneIv;

    private View mContentLat;

    private TabLayout mOrderTab;
    private ViewPager mOrderVpager;

    private List<Fragment> fragmentlist=new ArrayList<Fragment>();
    private FragmentAdapter mFragAdapter;
    private List<String>  mTitleList;
    private int index;
    private int allCount;
    private int casesCount;
    private int newCount;
    private int businessID;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home_shop_case);

        Intent intent = getIntent();
        if(intent!=null) {
            index = intent.getIntExtra("index", 1);
            allCount = intent.getIntExtra("allCount", 0);
            casesCount = intent.getIntExtra("casesCount", 0);
            newCount = intent.getIntExtra("newCount", 0);
            businessID = intent.getIntExtra("BusinessID", 0);
        }

        initview();

        initFragment();
    }

    private void initview() {

        mSearchEt = (EditText) findViewById(R.id.cate_search);
        mPhoneIv = (ImageView) findViewById(R.id.shop_pw);
        mBackLay = (LinearLayout) findViewById(R.id.lay_back);

        mContentLat =  findViewById(R.id.lay_content);

        mOrderTab = (TabLayout) findViewById(R.id.tabs_order);
        mOrderVpager = (ViewPager) findViewById(R.id.viewpager_order);



        mPhoneIv.setVisibility(View.GONE);

        mBackLay.setOnClickListener(this);


        String title1=allCount+"\r\n全部商品";
        String title2=casesCount+"\r\n案例";
        String title3=newCount+"\r\n新上架";
        mTitleList=new ArrayList<String>();
        mTitleList.add(title1);
        mTitleList.add(title2);
        mTitleList.add(title3);



    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
                case R.id.lay_back:

                    finish();

                break;

        }
    }

    private  void initFragment(){

        ShopAllGoodsFragment allGoodsFragment=new ShopAllGoodsFragment();
        ShopAllCaseFragment  allCaseFragment=new ShopAllCaseFragment();
        ShopAllNewFragment   allNewFragment=new ShopAllNewFragment();

        fragmentlist.add(allGoodsFragment);
        fragmentlist.add(allCaseFragment);
        fragmentlist.add(allNewFragment);
        mFragAdapter=new FragmentAdapter(getSupportFragmentManager(),mTitleList,fragmentlist);

        mOrderVpager.setAdapter(mFragAdapter);
        mOrderTab.setupWithViewPager(mOrderVpager);
        switch (index) {
                case 1:
                    mOrderVpager.setCurrentItem(0);
                break;
                 case 2:
                     mOrderVpager.setCurrentItem(1);
                break;
                 case 3:
                     mOrderVpager.setCurrentItem(2);
                break;
        }



    }




    public class FragmentAdapter extends FragmentPagerAdapter {

        private List<String> mTitles;
        private List<Fragment> fragmentlist;
        public FragmentAdapter(FragmentManager fm, List<String> titles, List<Fragment> fragmentlist) {
            super(fm);
            this.mTitles = titles;
            this.fragmentlist=fragmentlist;
        }

        private Fragment fragment;


        @Override
        public Fragment getItem(int position) {


            return fragmentlist.get(position);
        }

        @Override
        public int getCount() {
            return fragmentlist.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles.get(position);
        }

        @Override
        public int getItemPosition(Object object) {
            return PagerAdapter.POSITION_NONE;
        }

    }

    public int getBusinessID() {
        return businessID;
    }

    public void setBusinessID(int businessID) {
        this.businessID = businessID;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public int getCasesCount() {
        return casesCount;
    }

    public void setCasesCount(int casesCount) {
        this.casesCount = casesCount;
    }
}
